#include "searcher.hpp"
#include "cpp-httplib/httplib.h"
const std::string input = "data/raw_html/raw.txt";
const std::string root_path =  "./wwwroot";
int main()
{
    ns_searcher::Searcher searcher;
    searcher.InitSearcher(input);
    httplib::Server svr;
    svr.set_base_dir(root_path.c_str());
    svr.Get("/s",[&searcher](const httplib::Request &req, httplib::Response &rsq){
        if(!req.has_param("word"))
        {
            rsq.set_content("必须要有搜索关键字！", "text/plain; charset=utf-8");
            return;
        }
        std::string word = req.get_param_value("word");
        std::cout << "用户的搜索词为：" << word << std::endl;
        std::string json_string;
        searcher.Search(word,&json_string);
        rsq.set_content(json_string, "application/json; charset=utf-8");
    });
    svr.listen("0.0.0.0", 8080);

    return 0;
}



//在html中编写 !+Tab 可以自动补全代码
// if(!req.has_param("word"))
// {
//     rsq.set_content("请输入关键词", "text/plain; charset=utf-8");
//     return;
// }
// std::string word = req.get_param_value("word");
// std::cout << "用户的搜索词为：" << word << std::endl;
// std::string json_string;
// searcher.Search(word,&json_string);
// rsq.set_content(json_string, "application/json; charset=utf-8");